
var QQSound = cc.Class({


    statics: {

        effectPool : null,
        musicPool : {},
        /**
         * 播放音效
         * @param fileName
         */
        playEffect:function(fileName){
            if( !this.effectPool){
                this.effectPool = BK.createAudioContext({"type":"effect"});
            }
            this.effectPool.src = 'GameRes://res/raw-assets/resources/Sound/' + fileName;
            this.effectPool.play();
        },

        /**
         * 播放音乐
         * @param fileName
         * @param isLoop
         */
        playMusic:function(fileName,isLoop){
            if(!this.musicPool[fileName]){
                this.musicPool[fileName] = BK.createAudioContext();
                this.musicPool[fileName].loop = isLoop;
                this.musicPool[fileName].src = 'GameRes://res/raw-assets/resources/Sound/' + fileName;
            }
            this.musicPool[fileName].play();
        },

        stopMusic:function(fileName){
            if(fileName&&this.musicPool[fileName]){
                this.musicPool[fileName].pause();
                this.musicPool[fileName].destroy();
                this.musicPool[fileName] = null;
                return;
            }
            for(let p in this.musicPool){
                if (this.musicPool[p])
                {
                    this.musicPool[p].pause();
                    this.musicPool[p].destroy();
                    this.musicPool[p] = null;
                }

            }
        },

        /**
         * 暂停音乐
         * @param fileName
         */
        pauseMusic: function(fileName){
            if(fileName&&this.musicPool[fileName] ){
                this.musicPool[fileName].pause();
                return;
            }
            for(let p in this.musicPool){
                if (this.musicPool[p])
                    this.musicPool[p].pause();
            }
        },

        /**
         * 恢复音乐播放
         * @param fileName
         */
        resumeMusic:function(fileName){
            if(fileName&&this.musicPool[fileName]){
                this.musicPool[fileName].play();
                return;
            }
            for(let p in this.musicPool){
                if (this.musicPool[p])
                    this.musicPool[p].play();
            }
        }


    }
});

module.exports = QQSound;